document.addEventListener('DOMContentLoaded', function() {
    var btn = document.getElementById('submitbtn')
    btn.addEventListener('click', function() {
        var nameinput = document.getElementById('name')
        var usernameinput = document.getElementById('username')
        var mailinput = document.getElementById('mail')
        var subjectinput = document.getElementById('subject')
        var msginput = document.getElementById('message')
        var agreeinput = document.getElementById('agree')
        var content = 'name=' + nameinput.value + 
            '&username=' + usernameinput.value +
            '&email=' + mailinput.value +
            '&subject=' + subjectinput.value +
            '&message=' + msginput.value +
            '&agree=' + agreeinput.checked
        fetch('accept.do', {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            method: 'POST',
            body: content
        })
        .then(resp => {
            if (!resp.ok) {
                alert('无法提交表单！')
            }
            return resp.json()
        })
        .then(res => {
            if (res.ok) {
                location.replace('./profile.html')
            } else {
                alert('无法保存到服务器！')
            }
        })
    })
})
